package com.meixun.xuanke.user.service.impl;

import com.alibaba.fastjson.JSON;
import com.meixun.xuanke.user.model.LoginLog;
import com.meixun.xuanke.user.service.ActiveMQService;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.Destination;

@Service
public class ActiveMQServiceImpl implements ActiveMQService {

    @Resource
    private JmsTemplate jmsTemplate;

    //ActiveMQQueue 队列模式
    //ActiveMQTopic 订阅模式

    Destination loginLogDestination = new ActiveMQQueue("mq.userLoginLog");
    Destination textDestination = new ActiveMQQueue("mq.text");


    @Override
    public void addLoginLog(LoginLog loginLog) {
        jmsTemplate.convertAndSend(loginLogDestination, JSON.toJSON(loginLog).toString());
    }

    @Override
    public void sendText(String text) {
        jmsTemplate.convertAndSend(textDestination, text);
    }
}
